Inside Macintosh: Imaging with QuickDraw

Previous | Chapter Top | Chapter Contents | Next

Calculating Color Fills

Just as basic QuickDraw provides a pair of procedures ( SeedFill and CalcMask ) to help you determine the results of filling operations on portions of bitmaps, Color QuickDraw provides the SeedCFill and CalcCMask procedures to help you determine the results of filling operations on portions of pixel maps.

SeedCFill

To determine how far filling will extend to pixels matching the color of a particular pixel, use the SeedCFill procedure.

PROCEDURE SeedCFill (srcBits,dstBits: BitMap;
                                         srcRect,dstRect: Rect; seedH,seedV: Integer;
                                         matchProc: ProcPtr; matchData: LongInt);
srcBits
The source image. If the image is in a pixel map, you must coerce its PixMap record to a BitMap record.
dstBits
The destination mask.
srcRect
The rectangle of the source image.
dstRect
The rectangle of the destination image.
seedH
The horizontal position of the seed point.
seedV
The vertical position of the seed point.
matchProc
An optional color search function.
matchData
Data for the optional color search function.

DESCRIPTION

The SeedCFill procedure generates a mask showing where the pixels in an image can be filled from a starting point, like the paint pouring from the MacPaint paint-bucket tool. The SeedCFill procedure returns this mask in the dstBits parameter. This mask is a bitmap filled with 1's to indicate all pixels adjacent to a seed point whose colors do not exactly match the RGBColor record for the pixel at the seed point. You can then use this mask with the CopyBits , CopyMask , and CopyDeepMask procedures.

You specify a source image in the srcBits parameter, and in the srcRect parameter you specify a rectangle within that source image. You specify where to begin seeding in the seedH and seedV parameters, which must be the horizontal and vertical coordinates of a point in the local coordinate system of the source bitmap. By default, the 1's returned in the mask indicate all pixels adjacent to the seed point whose pixel values do not exactly match the pixel value of the pixel at the seed point. To use this default, set the matchProc and matchData parameters to 0.

In generating the mask, SeedCFill uses the CopyBits procedure to convert the source image to a 1-bit mask. The SeedCFill procedure installs a default color search function that returns 0 if the pixel value matches that of the seed point; all other pixel values return 1's.

The SeedCFill procedure does not scale: the source and destination rectangles must be the same size. Calls to SeedCFill are not clipped to the current port and are not stored into QuickDraw pictures.

You can customize SeedCFill by writing your own color search function and pointing to it in the matchProc procedure; SeedCFill will then use your procedure instead of the default. You can use the matchData parameter for whatever you'd like. In the matchData parameter, for instance, your application could pass the handle to a color table. Your color search function could then check whether the pixel value for the pixel currently under analysis matches any of the colors in the table.

SEE ALSO

See "Application-Defined Routine" for a description of how to customize the SeedCFill procedure.

CalcCMask

To determine where filling will not occur when filling from the outside of a rectangle, you can use the CalcCMask procedure, which indicates pixels that match, or are surrounded by pixels that match, a particular color.

PROCEDURE CalcCMask (srcBits,dstBits: BitMap;
                                         srcRect,dstRect: Rect;
                                         seedRGB: RGBColor; matchProc: ProcPtr;
                                         matchData: LongInt);
srcBits
The source image. If the image is in a pixel map, you must coerce its PixMap record to a BitMap record.
dstBits
The destination image, a BitMap record.
srcRect
The rectangle of the source image.
dstRect
The rectangle of the destination image.
seedRGB
An RGBColor record specifying the color for pixels that should not be filled.
matchProc
An optional matching procedure.
matchData
Data for the optional matching procedure.

DESCRIPTION

The CalcCMask procedure generates a mask showing where pixels in an image cannot be filled from any of the outer edges of the rectangle you specify. The CalcCMask procedure returns this mask in the dstBits parameter. This mask is a bitmap filled with 1's only where the pixels in the source image cannot be filled. You can then use this mask with the CopyBits , CopyMask , and CopyDeepMask procedures.

You specify a source image in the srcBits parameter, and in the srcRect parameter you specify a rectangle within that source image. Starting from the edges of this rectangle, CalcCMask calculates which pixels cannot be filled. By default, CalcCMask returns 1's in the mask to indicate which pixels have the exact color that you specify in the seedRGB parameter, as well as which pixels are enclosed by shapes whose outlines consist entirely of pixels with this color.

For instance, if the source image in srcBits contains a dark blue rectangle on a red background, and your application sets seedRGB equal to dark blue, then CalcCMask returns a mask with 1's in the positions corresponding to the edges and interior of the rectangle, and 0's outside of the rectangle.

If you set the matchProc and matchData parameters to 0, CalcCMask uses the exact color specified in the RGBColor record that you supply in the seedRGB parameter. You can customize CalcCMask by writing your own color search function and pointing to it in the matchProc procedure; your color search function might, for example, search for colors that approximate the color specified in the RGBColor record. As with SeedCFill , you can then use the matchData parameter in any manner useful for your application.

The CalcCMask procedure does not scale--the source and destination rectangles must be the same size. Calls to CalcCMask are not clipped to the current port and are not stored into QuickDraw pictures.

SEE ALSO

See "Application-Defined Routine" for a description of how to customize the CalcCMask procedure.


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next